package gcontent.rsrc;

import java.util.HashMap;

import gcontent.entities.site.SiteCache;
import gcontent.launch.SpiderThread;
import gcontent.record.db.RecordDB;

public class ThreadResources {
	
	public enum RSRC {
		SPIDER,
		CHANNEL_INS
	}
	
	private static HashMap<Long, SpiderThread> spider_list = new HashMap<Long, SpiderThread>();
	private static HashMap<Long, Object> channel_ins_list = new HashMap<Long, Object>();
	
	public static void registerResource(RSRC type, Object obj)
	{
		long tid;

		tid = Thread.currentThread().getId();
		switch(type) {
			case SPIDER:
				synchronized(spider_list) {	spider_list.put(tid, (SpiderThread)obj); }
				break;	
				
			case CHANNEL_INS:
				synchronized(channel_ins_list) { channel_ins_list.put(tid, obj); }
				break;					
		}
	}
	
	public static Object getResource(RSRC type)
	{
		long tid;
		Object ret_obj;
		
		tid = Thread.currentThread().getId();
		switch(type) {
			case SPIDER:
				synchronized(spider_list) {	ret_obj = spider_list.get(tid); }
				break;
				
			case CHANNEL_INS:
				synchronized(channel_ins_list) {	ret_obj = channel_ins_list.get(tid); }
				break;				
				
			default:
				
			ret_obj = null;
		}
		
		return ret_obj;
	}
}
